package chixing.day14.homework.work1;

import java.util.ArrayList;
import java.util.List;

public class Car {
    private List<Product> productList;

    public Car() {
        productList = new ArrayList<>();
    }

    // 增加
    public void add(Product product) {
        productList.add(product);
    }

    //根据下标获得
    public Product get(int index) {
        return productList.get(index);
    }
    //根据商品名称获得
    public Product get(String productName){
        for (Product p : productList) {
            if (p.getpName().equals(productName))
                return p;
        }
        return null;
    }
    //删除
//    public Product remove(int index){
//        return productList.remove(index);
//    }
    public Car remove(int index){
        productList.remove(index);
        return this;
    }

    //遍历
    public void display() {
        for (Product p : productList) {
            System.out.println(p);
        }
    }


    public List<Product> getProductList() {
        return productList;
    }

    public void setProductList(List<Product> productList) {
        this.productList = productList;
    }

    @Override
    public String toString() {
        return "Car{" +
                "productList=" + productList +
                '}';
    }
}
